﻿package mortal.game.view.forging.view
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.forging.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.view.compound.*;
    import mortal.game.view.palyer.*;
    import mortal.mvc.core.*;

    public class ForgingPanelBase extends GSprite
    {
        protected var _window:Window;
        protected var _leftImg2d:Img2D;
        protected var _bgData:BitmapData;
        protected var _currOperEquip:PlayerEquipItem;
        protected var _isCreateChildren:Boolean;

        public function ForgingPanelBase(param1:Window = null)
        {
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:String = null;
            super.createDisposedChildrenImpl();
            if (this is GemStrengthenPanel3)
            {
                _loc_1 = ImagesConst.ForgingGemBg;
            }
            else if (this is EquipRefreshPanel)
            {
                _loc_1 = ImagesConst.EquipRefreshBg;
            }
            else if (this is CompoundPanel)
            {
                _loc_1 = ImagesConst.SynthesisPanelLeftBg;
            }
            else if (this is EquipQualityAdvancePanel)
            {
                _loc_1 = ImagesConst.EquipStarUpgradeBg;
            }
            else
            {
                _loc_1 = ImagesConst.ForgingPanelBg;
            }
            LoaderManager.instance.load(_loc_1 + ".swf", this.onLoadCompl);
            return;
        }// end function

        protected function addEquipListeners() : void
        {
            Dispatcher.addEventListener(EventName.AddForgingEquip, this.onAddForgingEquipHandler);
            return;
        }// end function

        protected function removeEquipListeners() : void
        {
            Dispatcher.removeEventListener(EventName.AddForgingEquip, this.onAddForgingEquipHandler);
            return;
        }// end function

        protected function onLoadCompl(param1) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bgData = param1.bitmapData as BitmapData;
            this.add3DLayerBg();
            return;
        }// end function

        private function onPanelBgLoadCompl() : void
        {
            this.add3DLayerBg();
            return;
        }// end function

        public function updateUI() : void
        {
            return;
        }// end function

        protected function createChildren() : void
        {
            this._isCreateChildren = true;
            return;
        }// end function

        protected function onAddForgingEquipHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as PlayerEquipItem;
            this.addForgingEquip(_loc_2);
            return;
        }// end function

        public function addForgingEquip(param1:PlayerEquipItem) : void
        {
            this._currOperEquip.itemData = param1 == null ? (null) : (param1.itemData);
            return;
        }// end function

        public function updateForgingInfo() : void
        {
            return;
        }// end function

        public function clearUI() : void
        {
            if (this._currOperEquip)
            {
                this._currOperEquip.itemData = null;
                this._currOperEquip.updateStrengLevel();
            }
            return;
        }// end function

        private function init3dRect() : void
        {
            (this._window as ForgingModule).rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(11, 59 + 2, 763, 436), this._window);
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        private function change3dRect() : void
        {
            if (this is EquipDecomposePanel)
            {
                Rect3DManager.instance.changeRect3dArea(this._window, new Rectangle(11, 59 + 2, 763 - 270, 436));
            }
            else if (this is CompoundPanel)
            {
                Rect3DManager.instance.changeRect3dArea(this._window, new Rectangle(11, 59 + 2, 763 - 270, 436));
            }
            else
            {
                Rect3DManager.instance.changeRect3dArea(this._window, new Rectangle(11, 59 + 2, 763, 436));
            }
            return;
        }// end function

        protected function add3DLayerBg() : void
        {
            var _loc_1:* = (this._window as ForgingModule).rect3d;
            if (_loc_1 == null)
            {
                this.init3dRect();
                _loc_1 = (this._window as ForgingModule).rect3d;
            }
            this.change3dRect();
            if (_loc_1 != null)
            {
                _loc_1.removeImg(this._leftImg2d);
                this._leftImg2d = new Img2D(null, this._bgData, ForgingConst.Bg3DRect, false);
                _loc_1.addImg(this._leftImg2d);
            }
            return;
        }// end function

        protected function remove3DLayerBg() : void
        {
            var _loc_1:* = (this._window as ForgingModule).rect3d;
            if (_loc_1 && this._leftImg2d)
            {
                _loc_1.removeImg(this._leftImg2d);
                this._leftImg2d = null;
            }
            return;
        }// end function

        public function update3DModel() : void
        {
            return;
        }// end function

        protected function onEquipClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as PlayerEquipItem;
            if (_loc_2.itemData)
            {
                this.clearUI();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ResetCurrSelEquip));
            }
            return;
        }// end function

        protected function isConsumeItemEnough(param1:int, param2:int) : Boolean
        {
            var _loc_3:* = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, param1);
            if (param2 <= _loc_3)
            {
                return true;
            }
            return false;
        }// end function

        public function updateConsumeState() : void
        {
            return;
        }// end function

        public function updateMoneyState() : void
        {
            return;
        }// end function

        public function get currOperEquip() : PlayerEquipItem
        {
            return this._currOperEquip;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            isDisposed = true;
            this._bgData = null;
            this.remove3DLayerBg();
            return;
        }// end function

    }
}
